# 窗口相关的函数

def center_window(window, width=None, height=None):  
    """  
    Centers the window on the screen.  
  
    Parameters:  
        window (tk.Tk | tk.Toplevel): The window to be centered.  
        width (int, optional): The desired width of the window. Defaults to None.  
        height (int, optional): The desired height of the window. Defaults to None.  
    """  
    screen_width = window.winfo_screenwidth()  
    screen_height = window.winfo_screenheight()  
  
    # If no width/height are given, use the window's dimensions  
    if width is None:  
        width = window.winfo_reqwidth()  
    if height is None:  
        height = window.winfo_reqheight()  
  
    # Calculate position x, y  
    x = (screen_width // 2) - (width // 2)  
    y = (screen_height // 2) - (height // 2)  
    window.geometry(f"{width}x{height}+{int(x)}+{int(y)}")
